package com.molyfun.parents.activity.course.view.courseitem;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.common.GameViewerActivity;
import com.molyfun.parents.activity.course.bean.CourseMediaBean;
import com.molyfun.parents.dao.entity.SingleDownloadTask;
import com.molyfun.parents.rest.RestClient;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 */
public class CourseFileView extends BaseCourseView implements View.OnClickListener {

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.course_cell_image_img)
    ImageView mCourseCellImg;

    private SingleDownloadTask mSingleDownloadTask;

    public CourseFileView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public CourseFileView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public CourseFileView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.layout_course_cell_image, this);
        ButterKnife.inject(this);

    }

    /**
     * init view
     */
    public void initData(CourseMediaBean courseMediaBean) {
        super.initData(courseMediaBean);
        if (courseMediaBean == null) {
            return;
        }
        mCourseCellImg.setImageResource(R.mipmap.ic_file_holder);
        mCourseCellImg.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.course_cell_image_img:
                GameViewerActivity.startActivity(context, RestClient.ONLINE_OFFICE_FILE_URL_HEAD + mCourseMediaBean.getUrl());
                break;

        }
    }

}